package com.runen.infinitemovement.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.runen.infinitemovement.R;
import com.runen.infinitemovement.base.BaseActivity;
import com.runen.infinitemovement.model.api.UserAPI;
import com.runen.infinitemovement.model.entity.MessageEntity;
import com.runen.rxnetlibrary.net.callback.BaseResultCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyMessageActivity extends BaseActivity {

    @BindView(R.id.top_btn_left)
    Button topBtnLeft;
    @BindView(R.id.top_title)
    TextView topTitle;
    @BindView(R.id.iv_flag1)
    ImageView ivFlag1;
    @BindView(R.id.ll_focus)
    LinearLayout llFocus;
    @BindView(R.id.iv_flag2)
    ImageView ivFlag2;
    @BindView(R.id.ll_system)
    LinearLayout llSystem;
    @BindView(R.id.iv_flag3)
    ImageView ivFlag3;
    @BindView(R.id.ll_new_colleague)
    LinearLayout llNewColleague;
    @BindView(R.id.v_line)
    View vLine;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_my_message;
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        ButterKnife.bind(this);
        topTitle.setText("我的消息");
        initData();
    }

    private void initData() {
        showDialog();
        new UserAPI().onGetMessage(new BaseResultCallback<MessageEntity>() {
            @Override
            public void onResponse(MessageEntity response) {
                dismissDialog();
                if (response.code == 0) {
                    if (response.data != null) {
                        if (response.data.dynamics) {
                            ivFlag1.setVisibility(View.VISIBLE);
                        } else {
                            ivFlag1.setVisibility(View.GONE);
                        }
                        if (response.data.system) {
                            ivFlag2.setVisibility(View.VISIBLE);
                        } else {
                            ivFlag2.setVisibility(View.GONE);
                        }
                        if (response.data.isNewWorkmate) {
                            llNewColleague.setVisibility(View.GONE);
                            vLine.setVisibility(View.GONE);
                            if (response.data.newWorkmate) {
                                ivFlag3.setVisibility(View.VISIBLE);
                            } else {
                                ivFlag3.setVisibility(View.GONE);
                            }
                        } else {
                            llNewColleague.setVisibility(View.GONE);
                            vLine.setVisibility(View.GONE);
                        }
                    }
                }

            }
        });
    }

    @OnClick({R.id.top_btn_left, R.id.ll_focus, R.id.ll_system, R.id.ll_new_colleague})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.top_btn_left:
                finish();
                break;
            case R.id.ll_focus:
                ivFlag1.setVisibility(View.GONE);
                Intent intent = new Intent(this, FocusNotificationActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_system:
                ivFlag2.setVisibility(View.GONE);
                Intent intent3 = new Intent(this, SystemNotificationActivity.class);
                startActivity(intent3);
                break;
            case R.id.ll_new_colleague:
                ivFlag3.setVisibility(View.GONE);
                Intent intent2 = new Intent(this, NewColleagueActivity.class);
                startActivity(intent2);
                break;
        }
    }
}
